package logic

import (
	"context"
	"rpc/model/mysql"

	"rpc/internal/svc"
	"rpc/site"

	"github.com/zeromicro/go-zero/core/logx"
)

type AddTechnicianLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewAddTechnicianLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AddTechnicianLogic {
	return &AddTechnicianLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *AddTechnicianLogic) AddTechnician(in *site.AddTechnicianRequest) (*site.AddTechnicianResponse, error) {
	mobile := mysql.SyneMobile(in.Mobile)
	t := mysql.Technician{
		Name:   in.Name,
		Age:    int(in.Age),
		Sex:    in.Sex,
		Mobile: mobile,
		Images: in.Images,
		Price:  float64(in.Price),
	}
	err := t.Create()
	if err != nil {
		logx.Error("添加失败:", err)
		return nil, err
	}

	return &site.AddTechnicianResponse{}, nil
}
